<!DOCTYPE html>
<html lang="en">

<head>
    <#include "/lx/admin/components/meta.html" />
    <title>课程详情 ${metaTitleSuffix!}</title>
    <#include "/lx/admin/components/stylesheets.html" />
</head>

<body>
    <div id="app">
        <el-container>
            <#assign menuIndex="5-1" />
            <#include "/lx/admin/components/menu.html" />
            <el-container>
                <#include "/lx/admin/components/header.html" />
                <el-main>
                    <template>
                        <el-form ref="form" :model="info" label-width="100px">
                            <el-form-item label="课程名称">
                                <el-input v-model="info.title" placeholder="请输入课程名称"></el-input>
                            </el-form-item>
                            <el-form-item label="时长">
                                <el-input v-model="info.duration" placeholder="请输入时长"></el-input>
                            </el-form-item>
                            <el-form-item label="排序">
                                <el-input v-model="info.sort" type="number" placeholder="请输入排序"></el-input>
                            </el-form-item>
                            <el-form-item label="状态">
                                <el-radio-group v-model="info.status">
                                    <el-radio :label="1">正常</el-radio>
                                    <el-radio :label="0">禁用</el-radio>
                                </el-radio-group>
                            </el-form-item>
                            <el-form-item label="课程格式">
                                <el-radio-group v-model="info.isVideo">
                                    <el-radio :label="0">图片</el-radio>
                                    <el-radio :label="1">视频</el-radio>
                                </el-radio-group>
                            </el-form-item>
                            <el-form-item label="课程内容">
                                <el-input v-model="info.content" placeholder="请输入保利威视视频URL" v-if="info.isVideo == 1"></el-input>
                                <el-upload class="upload-demo" :http-request='uploadQnFile' :on-success='successImg' :on-preview="handlePreview" :on-remove="handleRemove" :file-list="fileList" list-type="picture-card" v-else>
                                    <el-button size="small" type="primary">选择文件</el-button>
                                </el-upload>
                            </el-form-item>
                            <!-- <el-form-item label="题目列表">
                                 <el-row>
                                       <el-col :span="12">
                                           <div class="operations">
                                               <el-button type="success" size="small" @click="add"><i class="el-icon-plus"></i>添加题目</el-button>
                                           </div>
                                       </el-col>
                                   </el-row>
                                   <el-table ref="multipleTable" :data="list" tooltip-effect="dark" :stripe='true' style="width: 100%">
                                       <el-table-column prop="title" label="题目">
                                       </el-table-column>
                                       <el-table-column fixed="right" label="操作" width="230">
                                           <template slot-scope="scope">
                                               <el-button @click="edit(scope.row)" type="text" size="small">编辑</el-button>
                                               <el-button @click="del(scope.row)" type="text" size="small" style="color: red;">删除</el-button>
                                           </template>
                                       </el-table-column>
                                   </el-table>
                            </el-form-item> -->
                            <el-form-item>
                                <el-button type="primary" @click="submit">提交</el-button>
                            </el-form-item>
                        </el-form>
                    </template>
                </el-main>
            </el-container>
        </el-container>
        <#include "/lx/admin/components/footer.html" />
    </div>
    <#include "/lx/admin/components/scripts.html" />
    <#include "/lx/admin/components/qiniu.html" />
    <script type="text/javascript">
    var vue = new Vue({
        el: '#app',
        data() {
            return {
                info: {},
                certificateId: '${certificateId!}',
                fileList: []
            }
        },
        watch: {},
        mounted: function() {
            this.info = ${info!'{}'}

            if (this.info.isVideo != 1 && this.info.content) {
                var images = this.info.content.split(';');
                images.pop();
                for (var i = 0; i < images.length; i ++) {
                    var filename = images[i].substring(images[i].lastIndexOf('/') + 1, images[i].indexOf('?') > 0 ? images[i].indexOf('?') : images[i].length );
                    var image = {
                      name: filename,
                      url: images[i]
                    }
                    this.fileList.push(image);
                }
            }
        },
        methods: {
            submit() {
                var self = this;
                if (typeof self.info.title == "undefined" || self.info.title == null || self.info.title.match(/^[ ]*$/)) {
                    msg("请输入课程名称");
                    return;
                }
                if (typeof self.info.duration == "undefined" || self.info.duration == null || self.info.duration.match(/^[ ]*$/)) {
                    msg("请输入时长");
                    return;
                }
                var content = '';
                if (self.info.isVideo != 1) {
                    for (var i = 0; i < self.fileList.length; i ++) {
                        content += self.fileList[i].url + ";";
                    }
                } else {
                    content = self.info.content;
                }
                if (!content) {
                    msg("请添加课程内容");
                    return;
                }

                var url = "/lx/admin/cert/submitCourse"
                var param = {
                    courseId: self.info.id,
                    certificateId: self.certificateId,
                    title: self.info.title,
                    duration: self.info.duration,
                    content: content,
                    sort: self.info.sort,
                    status: self.info.status,
                    isVideo: self.info.isVideo
                };
                var success = () => {
                    if ('${referer!}' != '') {
                        window.location.href = '${referer!}';
                    } else {
                        window.location.href = "/lx/admin/cert/courseList";
                    }
                }
                var fail = (response) => {
                    msg(response.data.msg);
                }
                var complete = () => {}
                axiosRequestPro(url, param, success, fail, complete);
            },
            successImg(response, file, fileList) {
                var image = {
                    name: file.name,
                    url: response.data.url
                }
                this.fileList.push(image);
            },
            handleRemove(file, fileList) {
                console.log(file, fileList);
                this.fileList = fileList;
            },
            handlePreview(file) {
                console.log(file);
                var layerOption = {
                    "title": "查看大图", //相册标题
                    "id": 0, //相册id
                    "start": 0, //初始显示的图片序号，默认0
                    "data": [ //相册包含的图片，数组格式
                        {
                            "alt": file.name,
                            "pid": file.uid, //图片id
                            "src": file.url, //原图地址
                            "thumb": "" //缩略图地址
                        }
                    ]
                }
                layer.photos({
                    photos: layerOption,
                    anim: 6
                })
            }
        }
    })
    </script>
    <style type="text/css">
    </style>
    <#include "/lx/admin/components/msg.html" />
</body>

</html>